home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdatetbl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-07-22  |  11.4 KB  |  448 lines

  1. /*  -*- C++ -*-
  2.     This file is part of the KDE libraries
  3.     Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
  4.               (C) 1998-2001 Mirko Boehm (mirko@kde.org)
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef KDATETBL_H
  21. #define KDATETBL_H
  22.  
  23. // KDE4: rename this file to kdatetable.h
  24.  
  25. #include <qvalidator.h>
  26. #include <qgridview.h>
  27. #include <qlineedit.h>
  28. #include <qdatetime.h>
  29. #include <qcolor.h>
  30.  
  31. #include <kdelibs_export.h>
  32.  
  33. class KPopupMenu;
  34.  
  35. /** Week selection widget.
  36. * @internal
  37. * @version $Id: kdatetbl.h 565029 2006-07-22 07:30:24Z kling $
  38. * @author Stephan Binner
  39. */
  40. class KDEUI_EXPORT KDateInternalWeekSelector : public QLineEdit
  41. {
  42.   Q_OBJECT
  43. protected:
  44.   QIntValidator *val;
  45.   int result;
  46. public slots:
  47.   void weekEnteredSlot();
  48.   void setMaxWeek(int max);
  49. signals:
  50.   void closeMe(int);
  51. public:
  52.   KDateInternalWeekSelector( QWidget* parent=0, const char* name=0);
  53.   int getWeek();
  54.   void setWeek(int week);
  55.  
  56. private:
  57.   class KDateInternalWeekPrivate;
  58.   KDateInternalWeekPrivate *d;
  59. };
  60.  
  61. /**
  62. * A table containing month names. It is used to pick a month directly.
  63. * @internal
  64. * @version $Id: kdatetbl.h 565029 2006-07-22 07:30:24Z kling $
  65. * @author Tim Gilman, Mirko Boehm
  66. */
  67. class KDEUI_EXPORT KDateInternalMonthPicker : public QGridView
  68. {
  69.   Q_OBJECT
  70. protected:
  71.   /**
  72.    * Store the month that has been clicked [1..12].
  73.    */
  74.   int result;
  75.   /**
  76.    * the cell under mouse cursor when LBM is pressed
  77.    */
  78.   short int activeCol;
  79.   short int activeRow;
  80.   /**
  81.    * Contains the largest rectangle needed by the month names.
  82.    */
  83.   QRect max;
  84. signals:
  85.   /**
  86.    * This is send from the mouse click event handler.
  87.    */
  88.   void closeMe(int);
  89. public:
  90.   /**
  91.    * The constructor.
  92.    */
  93.   KDateInternalMonthPicker(const QDate& date, QWidget* parent, const char* name=0);
  94.   /**
  95.    * The destructor.
  96.    */
  97.   ~KDateInternalMonthPicker();
  98.   /**
  99.    * The size hint.
  100.    */
  101.   QSize sizeHint() const;
  102.   /**
  103.    * Return the result. 0 means no selection (reject()), 1..12 are the
  104.    * months.
  105.    */
  106.   int getResult() const;
  107. protected:
  108.   /**
  109.    * Set up the painter.
  110.    */
  111.   void setupPainter(QPainter *p);
  112.   /**
  113.    * The resize event.
  114.    */
  115.   virtual void viewportResizeEvent(QResizeEvent*);
  116.   /**
  117.    * Paint a cell. This simply draws the month names in it.
  118.    */
  119.   virtual void paintCell(QPainter* painter, int row, int col);
  120.   /**
  121.    * Catch mouse click and move events to paint a rectangle around the item.
  122.    */
  123.   virtual void contentsMousePressEvent(QMouseEvent *e);
  124.   virtual void contentsMouseMoveEvent(QMouseEvent *e);
  125.   /**
  126.    * Emit monthSelected(int) when a cell has been released.
  127.    */
  128.   virtual void contentsMouseReleaseEvent(QMouseEvent *e);
  129.  
  130. private:
  131.   class KDateInternalMonthPrivate;
  132.   KDateInternalMonthPrivate *d;
  133. };
  134.  
  135. /** Year selection widget.
  136. * @internal
  137. * @version $Id: kdatetbl.h 565029 2006-07-22 07:30:24Z kling $
  138. * @author Tim Gilman, Mirko Boehm
  139. */
  140. class KDEUI_EXPORT KDateInternalYearSelector : public QLineEdit
  141. {
  142.   Q_OBJECT
  143. protected:
  144.   QIntValidator *val;
  145.   int result;
  146. public slots:
  147.   void yearEnteredSlot();
  148. signals:
  149.   void closeMe(int);
  150. public:
  151.   KDateInternalYearSelector( QWidget* parent=0, const char* name=0);
  152.   int getYear();
  153.   void setYear(int year);
  154.  
  155. private:
  156.   class KDateInternalYearPrivate;
  157.   KDateInternalYearPrivate *d;
  158.  
  159. };
  160.  
  161. /**
  162.  * Frame with popup menu behavior.
  163.  * @author Tim Gilman, Mirko Boehm
  164.  * @version $Id: kdatetbl.h 565029 2006-07-22 07:30:24Z kling $
  165.  */
  166. class KDEUI_EXPORT KPopupFrame : public QFrame
  167. {
  168.   Q_OBJECT
  169. protected:
  170.   /**
  171.    * The result. It is returned from exec() when the popup window closes.
  172.    */
  173.   int result;
  174.   /**
  175.    * Catch key press events.
  176.    */
  177.   virtual void keyPressEvent(QKeyEvent* e);
  178.   /**
  179.    * The only subwidget that uses the whole dialog window.
  180.    */
  181.   QWidget *main;
  182. public slots:
  183.   /**
  184.    * Close the popup window. This is called from the main widget, usually.
  185.    * @p r is the result returned from exec().
  186.    */
  187.   void close(int r);
  188.   /**
  189.    * Hides the widget. Reimplemented from QWidget
  190.    */
  191.   void hide();
  192.  
  193. public:
  194.   /**
  195.    * The contructor. Creates a dialog without buttons.
  196.    */
  197.   KPopupFrame(QWidget* parent=0, const char*  name=0);
  198.   /**
  199.    * The destructor.
  200.    */
  201.   ~KPopupFrame();
  202.   /**
  203.    * Set the main widget. You cannot set the main widget from the constructor,
  204.    * since it must be a child of the frame itselfes.
  205.    * Be careful: the size is set to the main widgets size. It is up to you to
  206.    * set the main widgets correct size before setting it as the main
  207.    * widget.
  208.    */
  209.   void setMainWidget(QWidget* m);
  210.   /**
  211.    * The resize event. Simply resizes the main widget to the whole
  212.    * widgets client size.
  213.    */
  214.   virtual void resizeEvent(QResizeEvent*);
  215.   /**
  216.    * Open the popup window at position pos.
  217.    */
  218.   void popup(const QPoint &pos);
  219.   /**
  220.    * Execute the popup window.
  221.    */
  222.   int exec(QPoint p); // KDE4: const QPoint&
  223.   /**
  224.    * Execute the popup window.
  225.    */
  226.   int exec(int x, int y);
  227.  
  228. private:
  229.  
  230.   virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); }
  231. protected:
  232.   virtual void virtual_hook( int id, void* data );
  233. private:
  234.   class KPopupFramePrivate;
  235.   KPopupFramePrivate *d;
  236. };
  237.  
  238. /**
  239. * Validates user-entered dates.
  240. */
  241. class KDEUI_EXPORT KDateValidator : public QValidator
  242. {
  243. public:
  244.     KDateValidator(QWidget* parent=0, const char* name=0);
  245.     virtual State validate(QString&, int&) const;
  246.     virtual void fixup ( QString & input ) const;
  247.     State date(const QString&, QDate&) const;
  248. };
  249.  
  250. /**
  251.  * Date selection table.
  252.  * This is a support class for the KDatePicker class.  It just
  253.  * draws the calender table without titles, but could theoretically
  254.  * be used as a standalone.
  255.  *
  256.  * When a date is selected by the user, it emits a signal:
  257.  * dateSelected(QDate)
  258.  *
  259.  * @internal
  260.  * @version $Id: kdatetbl.h 565029 2006-07-22 07:30:24Z kling $
  261.  * @author Tim Gilman, Mirko Boehm
  262.  */
  263. class KDEUI_EXPORT KDateTable : public QGridView
  264. {
  265.     Q_OBJECT
  266.     Q_PROPERTY( QDate date READ getDate WRITE setDate )
  267.     Q_PROPERTY( bool popupMenu READ popupMenuEnabled WRITE setPopupMenuEnabled )
  268.  
  269. public:
  270.     /**
  271.      * The constructor.
  272.      */
  273.     KDateTable(QWidget *parent=0, QDate date=QDate::currentDate(),
  274.            const char* name=0, WFlags f=0);
  275.  
  276.     /**
  277.      * The constructor.
  278.      * @since 3.4
  279.      */
  280.     KDateTable(QWidget *parent, const char* name, WFlags f=0);
  281.  
  282.     /**
  283.      * The destructor.
  284.      */
  285.     ~KDateTable();
  286.  
  287.     /**
  288.      * Returns a recommended size for the widget.
  289.      * To save some time, the size of the largest used cell content is
  290.      * calculated in each paintCell() call, since all calculations have
  291.      * to be done there anyway. The size is stored in maxCell. The
  292.      * sizeHint() simply returns a multiple of maxCell.
  293.      */
  294.     virtual QSize sizeHint() const;
  295.     /**
  296.      * Set the font size of the date table.
  297.      */
  298.     void setFontSize(int size);
  299.     /**
  300.      * Select and display this date.
  301.      */
  302.     bool setDate(const QDate&);
  303.     // ### KDE 4.0 rename to date()
  304.     const QDate& getDate() const;
  305.  
  306.     /**
  307.      * Enables a popup menu when right clicking on a date.
  308.      *
  309.      * When it's enabled, this object emits a aboutToShowContextMenu signal
  310.      * where you can fill in the menu items.
  311.      *
  312.      * @since 3.2
  313.      */
  314.     void setPopupMenuEnabled( bool enable );
  315.  
  316.     /**
  317.      * Returns if the popup menu is enabled or not
  318.      */
  319.     bool popupMenuEnabled() const;
  320.  
  321.     enum BackgroundMode { NoBgMode=0, RectangleMode, CircleMode };
  322.  
  323.     /**
  324.      * Makes a given date be painted with a given foregroundColor, and background
  325.      * (a rectangle, or a circle/ellipse) in a given color.
  326.      *
  327.      * @since 3.2
  328.      */
  329.     void setCustomDatePainting( const QDate &date, const QColor &fgColor, BackgroundMode bgMode=NoBgMode, const QColor &bgColor=QColor());
  330.  
  331.     /**
  332.      * Unsets the custom painting of a date so that the date is painted as usual.
  333.      *
  334.      * @since 3.2
  335.      */
  336.     void unsetCustomDatePainting( const QDate &date );
  337.  
  338. protected:
  339.     /**
  340.      * calculate the position of the cell in the matrix for the given date. The result is the 0-based index.
  341.      */
  342.     int posFromDate( const QDate &date ); // KDE4: make this virtual, so subclasses can reimplement this and use a different default for the start of the matrix
  343.     /**
  344.      * calculate the date that is displayed at a given cell in the matrix. pos is the
  345.      * 0-based index in the matrix. Inverse function to posForDate().
  346.      */
  347.     QDate dateFromPos( int pos ); // KDE4: make this virtual
  348.  
  349.     /**
  350.      * Paint a cell.
  351.      */
  352.     virtual void paintCell(QPainter*, int, int);
  353.  
  354.     /**
  355.      * Paint the empty area (background).
  356.      */
  357.     virtual void paintEmptyArea(QPainter*, int, int, int, int);
  358.  
  359.     /**
  360.      * Handle the resize events.
  361.      */
  362.     virtual void viewportResizeEvent(QResizeEvent *);
  363.     /**
  364.      * React on mouse clicks that select a date.
  365.      */
  366.     virtual void contentsMousePressEvent(QMouseEvent *);
  367.     virtual void wheelEvent( QWheelEvent * e );
  368.     virtual void keyPressEvent( QKeyEvent *e );
  369.     virtual void focusInEvent( QFocusEvent *e );
  370.     virtual void focusOutEvent( QFocusEvent *e );
  371.  
  372.     // ### KDE 4.0 make the following private and mark as members
  373.  
  374.     /**
  375.      * The font size of the displayed text.
  376.      */
  377.     int fontsize;
  378.     /**
  379.      * The currently selected date.
  380.      */
  381.     QDate date;
  382.     /**
  383.      * The day of the first day in the month [1..7].
  384.      */
  385.     int firstday;
  386.     /**
  387.      * The number of days in the current month.
  388.      */
  389.     int numdays;
  390.     /**
  391.      * The number of days in the previous month.
  392.      */
  393.     int numDaysPrevMonth;
  394.     /**
  395.      * unused
  396.      * ### remove in KDE 4.0
  397.      */
  398.     bool unused_hasSelection;
  399.     /**
  400.      * Save the size of the largest used cell content.
  401.      */
  402.     QRect maxCell;
  403. signals:
  404.     /**
  405.      * The selected date changed.
  406.      */
  407.     // ### KDE 4.0 make parameter a const reference
  408.     void dateChanged(QDate);
  409.     /**
  410.      * This function behaves essentially like the one above.
  411.      * The selected date changed.
  412.      * @param cur The current date
  413.      * @param old The date before the date was changed
  414.      */
  415.     void dateChanged(const QDate& cur, const QDate& old);
  416.     /**
  417.      * A date has been selected by clicking on the table.
  418.      */
  419.     void tableClicked();
  420.  
  421.     /**
  422.      * A popup menu for a given date is about to be shown (as when the user
  423.      * right clicks on that date and the popup menu is enabled). Connect
  424.      * the slot where you fill the menu to this signal.
  425.      *
  426.      * @since 3.2
  427.      */
  428.     void aboutToShowContextMenu( KPopupMenu * menu, const QDate &date);
  429.  
  430. private slots:
  431.   void nextMonth();
  432.   void previousMonth();
  433.   void beginningOfMonth();
  434.   void endOfMonth();
  435.   void beginningOfWeek();
  436.   void endOfWeek();
  437.  
  438. protected:
  439.   virtual void virtual_hook( int id, void* data );
  440. private:
  441.     class KDateTablePrivate;
  442.     KDateTablePrivate *d;
  443.   
  444.   void initAccels();
  445. };
  446.  
  447. #endif // KDATETBL_H
  448.